chore: multipart upload ETag normalization and add debug logging#9
Closed
chore: multipart upload ETag normalization and add debug logging#9
Conversation
- Add strings import for ETag processing - Normalize ETag values by trimming quotes from S3 responses - Add debug logging when appending parts - Add pre-completion validation logging showing part count and ETags - Mutex protection already in place for parts slice append Co-authored-by: bwalsh <47808+bwalsh@users.noreply.github.com>
Co-authored-by: bwalsh <47808+bwalsh@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix multipart upload failures and ETag normalization
Fix multipart upload ETag normalization and add debug logging
Nov 19, 2025
Contributor
|
@copilot Read UploadSingleMultipart is it thread safe? |
Author
The
The mutex should ideally be per-upload (local variable) rather than global. The current global mutex works because:
Would you like me to refactor to use a per-upload mutex instead of the global one? |
Collaborator
|
added in another branch see 4089807 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Multipart uploads fail intermittently because S3 returns quoted ETags (
"abc123") butCompleteMultipartUploadexpects unquoted values. The existing mutex protection for the parts slice was already correct.Changes
ETag normalization: Trim quotes from S3 ETag responses before storing in parts array
Debug logging: Added logging when appending parts and before completion to aid diagnosis of future failures
CompleteMultipartUploadImport: Added
stringspackage for ETag processingAlternative approaches considered
The minimal mutex+trim approach fixes the immediate ETag mismatch with lowest risk.
Original prompt
Problem summary
Users report intermittent failures during multipart uploads with logs like "error uploading file to bucket: multipart upload failed". Investigation shows the multipart upload implementation (gen3-client/g3cmd/upload-multipart.go) appends to a shared parts slice from multiple goroutines without synchronization, which is a data race and can lead to corrupted or missing part entries. Additionally, ETag values returned by S3-like services are often quoted (e.g., ""abc123""), and the code does not normalize/trims ETag quotes before sending the CompleteMultipartUpload request, which can cause completion to fail.
Goal
Create a small, focused patch that:
Files to change
").Change rationale
Patch requirements
Other alternatives (analysis)
Below is a writeup of a more defensive rework that reduces locking contention and adds validation before completing the multipart upload.
Pros: reduces lock contention and potential for contention under many small parts; cleaner semantics.
Cons: requires more code changes and memory for per-worker buffers, but memory is proportional to number of parts, not chunk size.
Pros: simple to reason about; avoids locks entirely.
Cons: requires channel read loop and coordination to close the channel when all workers are done.
Why the minimal mutex+ETag trim is chosen
PR contents & testing notes
Modify gen3-client/g3cmd/upload-multipart.go to:
")Run
go veta...This pull request was created as a result of the following prompt from Copilot chat.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.